// pages/index/temporary/impredra.js
//var postData = require('../../data/post-data.js')
var app = getApp();
var page = 1
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clickId: -1,
    clickIds: -1,
    clickIdse: -1,
    clickIdses: -1,
    icon_imagef: "https://img.xtuan.com/xcximgtest/images/materal/down.png",
    icon_imagec: "https://img.xtuan.com/xcximgtest/images/materal/down.png",
    icon_imaget: "https://img.xtuan.com/xcximgtest/images/materal/down.png",
    icon_imageg: "https://img.xtuan.com/xcximgtest/images/materal/down.png",
    th_style: "风格",
    th_house: "户型",
    th_space: "空间",
    th_alear: "面积",
    styleID: '0',
    homeID: '0',
    spaceID: '0',
    squareID: '0',
    page: 1,
    arrys: [],
    comid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    let dataArr = options.data.split(',');
    console.log(dataArr)
    console.log(options)
    var comid = dataArr[0];
    var company = dataArr[1]

    wx.request({
      url: app.apiUrl('c=rendering/index&a=getconfig'),
      data: {
       companyID:comid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)
        var polistdata = res.data.data.style
        var houstyle = res.data.data.home
        var thespace = res.data.data.space
        var thearea = res.data.data.square
        that.setData({
          polists: polistdata,
          housty: houstyle,
          space: thespace,
          square: thearea,
          comid: comid
          // styles:style
        })
        that.getlist()
        wx.setNavigationBarTitle({
          title: company //页面标题为路由参数
        })
      }
      
    })
    that.setData({
      // houstyles: postData.styles,
      // huxing: postData.housstyle,
      // the_aceage: postData.thehosealear,
      // the_space: postData.spaces
      comid:comid
    })
    console.log(that.data)
  },
  //数据列表
  getlist: function (e) {
    var that = this
    var comid = that.data.comid
    console.log(comid )
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      data: {companyID:comid},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var listdata = that.data.arrys
        var thepolist = res.data.data
        var styleID = thepolist.length
        for (var i = 0; i <= styleID; i++) {
          var s = thepolist[i]
          //listdata.push(res.data.data[i]);
        }
        console.log(styleID)
        that.setData({
          polistses: thepolist,
        })
      }
    })
  },
  onShow: function () {

  },


  //头部导航点击事件
  chose_style: function () {
    var that = this
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      the_styles: true,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: true,
      the_stlec: the_color,
      the_housec: other,
      the_spacec: other,
      the_alearc: other,
      icon_imagef: icondown,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
    })
  },
  chose_house: function () {
    var that = this
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      the_styles: false,
      biffstyle: true,
      show_space: false,
      show_alear: false,
      showMask: true,
      the_stlec: other,
      the_housec: the_color,
      the_spacec: other,
      the_alearc: other,
      icon_imagef: sames_image,
      icon_imagec: icondown,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
    })
  },
  chose_space: function () {
    var that = this
    var martop = 0;
    var positions = 'fixed'
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      the_styles: false,
      biffstyle: false,
      show_space: true,
      show_alear: false,
      showMask: true,
      martop: martop,
      status: positions,
      the_stlec: other,
      the_housec: other,
      the_spacec: the_color,
      the_alearc: other,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: icondown,
      icon_imageg: sames_image,
    })
  },
  chos_alear: function () {
    var that = this
    var martop = 0;
    var positions = 'fixed'
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: true,
      showMask: true,
      martop: martop,
      status: positions,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: the_color,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: icondown,
    })
  },






  //弹框内容点击事件
  choose_acerage: function (e) {
    var that = this;
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var length = that.data.clickId;
    var index = e.currentTarget.id;
    var comid = that.data.comid
    var other = "rgb(153,153,153)";
    var page = 1
    //var index = parseInt(e.currentTarget.id);
    var value = that.data.polists[index];
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    if (this.data.clickId == e.currentTarget.id) {
      this.setData({
        clickId: 1,
        the_miji: value
      })
      return;
    }
    wx.pageScrollTo({
      scrollTop: 0
    })
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        style: index,
        home: homeID,
        space: spaceID,
        square: squareID,
        page: page,
        companyID:comid
      },
      success: function (res) {
        var polist = res.data.data
        that.setData({
          polistses: polist
        })
      }
    })
    that.setData({
      clickId: e.currentTarget.id,
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: other,
      th_style: value,
      styleID: index,
      page: page
    })
    //console.log(index)
    console.log(that.data.page)
  },
  choose_house: function (e) {
    var that = this;
    var page = 1
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var index = e.currentTarget.id;
    var length = that.data.clickIds;
    var comid = that.data.comid
    //var index = parseInt(e.currentTarget.id);
    var value = that.data.housty[index];
    var other = "rgb(153,153,153)";
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    if (this.data.clickIds == e.currentTarget.id) {
      this.setData({
        clickIds: 1,
        the_miji: value
      })
      return;
    }
    wx.pageScrollTo({
      scrollTop: 0
    })
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        home: index,
        style: styleID,
        space: spaceID,
        square: squareID,
        page: page,
        companyID:comid
      },
      success: function (res) {
        var polist = res.data.data
        console.log(res.data)
        that.setData({
          polistses: polist
        })
      }
    })
    that.setData({
      clickIds: e.currentTarget.id,
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: other,
      th_house: value,
      homeID: index,
      page: page
    })
    console.log(index)
  },

  choose_space: function (e) {
    var that = this;
    var page = 1
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var index = e.currentTarget.id;
    var comid = that.data.comid
    //var index = parseInt(e.currentTarget.id);
    var value = that.data.space[index];
    var other = "rgb(153,153,153)";
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    if (this.data.clickIdse == e.currentTarget.id) {
      this.setData({
        clickIdse: 1,
        the_miji: value
      })
      return;
    }
    wx.pageScrollTo({
      scrollTop: 0
    })
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        space: index,
        style: styleID,
        home: homeID,
        square: squareID,
        page: page,
        companyID:comid
      },
      success: function (res) {
        var polist = res.data.data
        console.log(res.data)
        that.setData({
          polistses: polist
        })
      }
    })
    that.setData({
      clickIdse: e.currentTarget.id,
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: other,
      th_space: value,
      spaceID: index,
      page: page
    })
    console.log(index)
  },
  choose_price: function (e) {
    var that = this;
    var page = 1
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var index = e.currentTarget.id;
    var comid = that.data.comid
    //var index = parseInt(e.currentTarget.id);
    var value = that.data.square[index];
    var other = "rgb(153,153,153)";
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    if (this.data.clickIdses == e.currentTarget.id) {
      this.setData({
        clickIdses: 1,
        the_miji: value
      })
      return;
    }
    wx.pageScrollTo({
      scrollTop: 0
    })
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        square: index,
        style: styleID,
        home: homeID,
        space: spaceID,
        page: page,
        companyID:comid
      },
      success: function (res) {
        var polist = res.data.data
        console.log(res.data)
        that.setData({
          polistses: polist
        })
      }
    })
    that.setData({
      clickIdses: e.currentTarget.id,
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: other,
      th_alear: value,
      squareID: index,
      page: page
    })
    console.log(index)
  },

  //阻止默认事件
  stopmove: function (e) {
    that.setData({
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
    })
  },
  clickmodel: function (e) {
    var that = this
    var other = "rgb(153,153,153)";
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    that.setData({
      the_styles: false,
      biffstyle: false,
      show_space: false,
      show_alear: false,
      showMask: false,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      icon_imageg: sames_image,
      the_stlec: other,
      the_housec: other,
      the_spacec: other,
      the_alearc: other
    })
  },
  preventTouchMove: function (e) { },
  stopTouchMove: function (e) { },
  noTouchMove: function (e) { },
  TouchMove: function (e) { },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  binddetail: function (e) {
    var num = parseInt(e.currentTarget.dataset.index);
    var id = this.data.polistses[num].renderingID
    wx.navigateTo({
      url: "../../impredra/impredra_detail?id=" + id
    })
    // console.log(this.data);
    // console.log(id);
  },
  //上拉加载
  onReachBottom: function () {
    var that = this
    that.setData({
      page: that.data.page + 1 //后台数据需要分页，每次加载一页
    })
    wx.showLoading({ //显示toast
      title: '加载中...',
    });
    //var page = that.data.page
    var page = that.data.page
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var length = that.data.clickId;
    var comid = that.data.comid
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      data: {
        page: that.data.page,
        square: styleID,
        style: styleID,
        home: homeID,
        space: spaceID,
        companyID:comid
      },
      method: 'GET',
      success: function (res) {
        var listdata = that.data.polistses
        for (var i = 0; i < res.data.data.length; i++) {
          listdata.push(res.data.data[i]);
        }
        that.setData({
          polistses: listdata
        });
        page++
        console.log(page)
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
        wx.hideNavigationBarLoading() //完成停止加载
        wx.hideLoading(); //隐藏
      }
    })
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var that = this
    var page = that.data.page
    var styleID = that.data.styleID
    var homeID = that.data.homeID
    var spaceID = that.data.spaceID
    var squareID = that.data.squareID
    var comid = that.data.comid
    // wx.showLoading({
    //   title: '数据加载中',
    // })
    wx.request({
      url: app.apiUrl('c=rendering/index&a=getlist'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        //page: that.data.page,
        square: styleID,
        style: styleID,
        home: homeID,
        space: spaceID,
        companyID:comid
      },
      success: function (res) {
        var polist = res.data.data
        that.setData({
          polistses: polist
        })
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
        wx.stopPullDownRefresh() //停止下拉刷新
      }
    })
  },


})